<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8" import="com.zzty.springmybatis.entity.User"%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>ZZTY</title>
<!-- BOOTSTRAP STYLES-->
<link href="../css/bootstrap.css" rel="stylesheet" />
<link href="../css/bootstrap-datetimepicker.css" rel="stylesheet" />
<!-- CUSTOM STYLES-->
<link href="../css/custom.css" rel="stylesheet" />
<script
	src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script
	src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>


<script type="text/javascript">
			
		</script>
</head>

<script type="text/javascript">
$(document).ready(function() {
	var page=0;
	var maxPage=0;
	$.ajax({
		type : "GET",
		url : "../SearchScore/searchMax",
		contentType : "application/json",
		success : function(data) {
			maxPage=data;
			if(page==maxPage){
				
				$("#downPage").attr({"disabled":"disabled"});
			}
		},
		error : function(data) {
		}
	})
	$.ajax({
				type : "GET",
				url : "../SearchScore/search/"+page,
				contentType : "application/json",
				success : function(data) {
					showInTable(data);
				},
				error : function(data) {
					alert(data + "error");
				}
			})
	
	
	
	
	$("#upPage").attr({"disabled":"disabled"});
		$("#upPage").click(function(){
			page-=1;
			if(page==0){
				$("#upPage").attr({"disabled":"disabled"});
				
			}
			if(page<maxPage){
				$("#downPage").removeAttr("disabled");
				
			}
			$.ajax({
				type : "GET",
				url : "../SearchScore/search/"+page,
				contentType : "application/json",
				success : function(data) {
					showInTable(data);
				},
				error : function(data) {
					alert(data + "error");
				}
			})
			
			
		})
		$("#downPage").click(function(){
			
			page+=1;
			if(page>0){
				$("#upPage").removeAttr("disabled");
				
			}
			if(page=maxPage){
				$("#downPage").attr({"disabled":"disabled"});
				
			}
			$.ajax({
				type : "GET",
				url : "../SearchScore/search/"+page,
				contentType : "application/json",
				success : function(data) {
					showInTable(data);
				},
				error : function(data) {
					alert(data + "error");
				}
			})
			
			
		})
		
		
			function showInTable(result) {
							$("#tbody1").empty();
							
							var obj = JSON.parse(result);

							var names = obj[0][0].names.split("_");
							var newTrName = "<tr><td>" + "	      竞赛	  "
									+ "</td>";
							for ( var j in names) {
								newTrName += "<td>" + names[j] + "</td>";

							}
							newTrName += "</tr>";
							$("#tbody1").append(newTrName);
							// 			var newTrNames = document.getElementById("table1").insertRow();
							// 			var newTdNull = newTrNames.insertCell();
							// 			newTdNull.innerText = "	      竞赛	  ";
							// 			for ( var j in names) {
							// 				var newTd = newTrNames.insertCell();
							// 				newTd.innerText = names[j];
							// 			}

							for ( var i in obj[0]) {

								var newTr = "<tr><td>" + obj[0][i].date
										+ "</td>";
								var scores = obj[0][i].scores.split("_");
								for ( var j in scores) {

									newTr += "<td>" + scores[j] + "</td>";

								}
								newTr += "</tr>";
								$("#tbody1").append(newTr);
							}
							var newTrEmpty = "<tr><td></td>";
							// 			var newTrEmpty = document.getElementById("table1").insertRow();

							var names2 = obj[1][0].names.split("_");
							var newTrNames2 = "<tr><td>" + "	      结对	  "
									+ "</td>";

							for ( var j in names2) {
								newTrEmpty += "<td></td>";
								newTrNames2 += "<td>" + names2[j] + "</td>";
							}
							newTrEmpty += "</tr>";
							newTrNames2 += "</tr>";
							$("#tbody1").append(newTrEmpty);
							$("#tbody1").append(newTrNames2);

							for ( var i in obj[1]) {

								var newTr = "<tr><td>" + obj[1][i].date
										+ "</td>";
								// 				var newTdDate = newTr.insertCell();
								// 				newTdDate.innerText = obj[1][i].date;
								var scores = obj[1][i].scores.split("_");
								for ( var j in scores) {
									newTr += "<td>" + scores[j] + "</td>";
									// 					var newTd = newTr.insertCell();
									// 					newTd.innerText = scores[j];
								}
								newTr += "</tr>";
								$("#tbody1").append(newTr);
							}
							$("#ebutton").show();
							// 			document.getElementById("ebutton").style.display = "";
						}
						var allDate = "";
						function getDate(datestr) {
							var temp = datestr.split("-");
							var date = new Date(temp[0], temp[1], temp[2]);
							return date;
						}
						function getAllDate() {
							var start = $("#date1").val();
							var end = $("#date2").val();
							// 							var start = document.getElementById("date1").value;
							// 							var end = document.getElementById("date2").value;
							var startTime = getDate(start);
							var endTime = getDate(end);
							while ((endTime.getTime() - startTime.getTime()) >= 0) {
								var year = startTime.getFullYear();
								var month = startTime.getMonth().toString().length == 1 ? "0"
										+ startTime.getMonth().toString()
										: startTime.getMonth();
								var day = startTime.getDate().toString().length == 1 ? "0"
										+ startTime.getDate()
										: startTime.getDate();
								var targetdate = year + "-" + month + "-" + day;
								allDate += (targetdate + "_");
								startTime.setDate(startTime.getDate() + 1);
							}
						}
						
// 						function getXlsFromJsp(id) {
							
// 						}
						
						$("#ebutton").click(function(){
							var form_excel = document.createElement("form");
							document.body.appendChild(form_excel);
							form_excel.action = "../ExcelCreate.jsp?tableid=table1" ;
							form_excel.method = "post";
							form_excel.setAttribute("accept-charset", "utf-8");
							var table_inn = document.createElement("input");

							table_inn.name = "tablevalue2";
							table_inn.type = "hidden";
							table_inn.value = document.getElementById("table1").innerHTML;
							form_excel.appendChild(table_inn);
							form_excel.submit();
						})
						
						
					})
// 	function ajaxCall(method, url, callBackFunction, date) {

// 		var httprequest = new XMLHttpRequest();
// 		httprequest.onreadystatechange = function() {
// 			if (httprequest.readyState == 4 && httprequest.status == 200) {
// 				callBackFunction(httprequest.responseText);
// 			}
// 		}
// 		httprequest.open(method, url, true);
// 		httprequest.setRequestHeader("X-Requested-With", "AJAX");
// 		httprequest.send(date);
// 	}

// 	function clearTable() {
// 		var tb = document.getElementById('table1');
// 		var rowNum = tb.rows.length;
// 		for (i = 1; i < rowNum; i++) {
// 			tb.deleteRow(i);
// 			rowNum = rowNum - 1;
// 			i = i - 1;
// 		}
// 	}

// 	function getDate(datestr) {
// 		var temp = datestr.split("-");
// 		var date = new Date(temp[0], temp[1], temp[2]);
// 		return date;
// 	}

// 	var allDate = "";

// 	function getAllDate() {
// 		var start = document.getElementById("date1").value;
// 		var end = document.getElementById("date2").value;
// 		var startTime = getDate(start);
// 		var endTime = getDate(end);
// 		while ((endTime.getTime() - startTime.getTime()) >= 0) {
// 			var year = startTime.getFullYear();
// 			var month = startTime.getMonth().toString().length == 1 ? "0"
// 					+ startTime.getMonth().toString() : startTime.getMonth();
// 			var day = startTime.getDate().toString().length == 1 ? "0"
// 					+ startTime.getDate() : startTime.getDate();
// 			var targetdate = year + "-" + month + "-" + day;
// 			allDate += (targetdate + "_");
// 			startTime.setDate(startTime.getDate() + 1);
// 		}
// 	}

// 	function searchByDate() {
// 		allDate = "";
// 		getAllDate();
// 		ajaxCall("Post", "../SearchScoreServlet", showInTable, allDate);
// 	}

// 	function showInTable(result) {
// 		clearTable();
// 		var obj = JSON.parse(result);

// 		var names = obj[0][0].names.split("_");
// 		var newTrNames = document.getElementById("table1").insertRow();
// 		var newTdNull = newTrNames.insertCell();
// 		newTdNull.innerText = "	      竞赛	  ";
// 		for ( var j in names) {
// 			var newTd = newTrNames.insertCell();
// 			newTd.innerText = names[j];
// 		}

// 		for ( var i in obj[0]) {
// 			var newTr = document.getElementById("table1").insertRow();
// 			var newTdDate = newTr.insertCell();
// 			newTdDate.innerText = obj[0][i].date;
// 			var scores = obj[0][i].scores.split("_");
// 			for ( var j in scores) {
// 				var newTd = newTr.insertCell();
// 				newTd.innerText = scores[j];
// 			}
// 		}

// 		var newTrEmpty = document.getElementById("table1").insertRow();

// 		var names2 = obj[1][0].names.split("_");
// 		var newTrNames2 = document.getElementById("table1").insertRow();
// 		var newTdNull2 = newTrNames2.insertCell();
// 		newTdNull2.innerText = "	      结对	  ";
// 		for ( var j in names2) {
// 			var newTdEmpty = newTrEmpty.insertCell();
// 			var newTd = newTrNames2.insertCell();
// 			newTd.innerText = names2[j];
// 		}

// 		for ( var i in obj[1]) {
// 			var newTr = document.getElementById("table1").insertRow();
// 			var newTdDate = newTr.insertCell();
// 			newTdDate.innerText = obj[1][i].date;
// 			var scores = obj[1][i].scores.split("_");
// 			for ( var j in scores) {
// 				var newTd = newTr.insertCell();
// 				newTd.innerText = scores[j];
// 			}
// 		}
// 		document.getElementById("ebutton").style.display = "";
// 	}

// 	function getXlsFromJsp(id) {
// 		var form_excel = document.createElement("form");
// 		document.body.appendChild(form_excel);
// 		form_excel.action = "../jsp/ExcelCreate.jsp?tableid=" + id;
// 		form_excel.method = "post";
// 		form_excel.setAttribute("accept-charset", "utf-8");
// 		var table_inn = document.createElement("input");

// 		table_inn.name = "tablevalue2";
// 		table_inn.type = "hidden";
// 		table_inn.value = document.getElementById(id).innerHTML;
// 		form_excel.appendChild(table_inn);
// 		form_excel.submit();
// 	}
<%-- <%User user = (User) request.getSession().getAttribute("user"); --%>
<%-- 			String img = (String) user.getImg();%> --%>
	
</script>

<body>
	<div id="wrapper">
		<nav class="navbar navbar-default navbar-cls-top " role="navigation"
			style="margin-bottom: 0">
			<div class="navbar-header">
				<!--                 <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".sidebar-collapse"> -->
				<!--                     <span class="sr-only">Toggle navigation</span> -->
				<!--                     <span class="icon-bar"></span> -->
				<!--                     <span class="icon-bar"></span> -->
				<!--                     <span class="icon-bar"></span> -->
				<!--                 </button> -->
				<a class="navbar-brand">自在天原</a>
			</div>
			<div
				style="color: white; padding: 15px 50px 5px 50px; float: right; font-size: 16px;">
				<form action="../loginOut.jsp" method="post">
					<button type="submit" class="btn btn-danger">注销</button>
				</form>
			</div>
		</nav>
		<!-- /. NAV TOP  -->
		<nav class="navbar-default navbar-side" role="navigation">
			<div class="sidebar-collapse">
				<ul class="nav" id="main-menu">
					<%-- 					<li class="text-center"><img src="<%=img%>" --%>
					<!-- 						class="user-image img-responsive" /></li> -->

					<li class="text-center"><img src=""
						class="user-image img-responsive" /></li>
					<!-- 					<li><a href="../index.jsp"><i -->
					<!-- 							class="fa fa-dashboard fa-3x"></i> 主页</a></li> -->
					<!-- 					<li><a href="UserInfo.jsp"><i class="fa fa-table fa-3x"></i> -->
					<!-- 							个人信息</a></li> -->
					<li><a href="../selfgread"><i class="fa fa-desktop fa-3x"></i>
							竞赛批改</a></li>
					<li><a href="../teamgread"><i class="fa fa-qrcode fa-3x"></i>
							结对批改</a></li>
					<li><a href="../que/AssginTask"><i
							class="fa fa-bar-chart-o fa-3x"></i> 竞赛布置</a></li>
					<li><a href="../group/group"><i
							class="fa fa-bar-chart-o fa-3x"></i> 结对分组</a></li>
					<li><a href="../SearchScore/toSearch"><i
							class="fa fa-bar-chart-o fa-3x"></i> 学生成绩</a></li>
					<li><a href="../Data"><i class="fa fa-bar-chart-o fa-3x"></i>
							数据库查询</a></li>
					<!-- 					<li><a href="ChangePassword.jsp"><i -->
					<!-- 							class="fa fa-edit fa-3x"></i> 密码修改 </a></li> -->

				</ul>

			</div>

		</nav>
		<!-- /. NAV SIDE  -->
		<div id="page-wrapper">
			<div id="page-inner">

				<div class="container">
					<fieldset>
						<legend>学生成绩查询</legend>
						<p>


							<button id="upPage">上一页</button>
							<button id="downPage">下一页</button>
						</p>

						<div class="row" style="padding: 50px 20px 0px 20px">

							<div class="table-responsive">
								<table class="table table-striped" id="table1"
									style="text-align: center">
									<thead>
										<tr>

										</tr>
									</thead>

									<tbody id="tbody1">


									</tbody>
								</table>
							</div>
						</div>
						<div class="col-sm-offset-5 col-sm-7">
							<input id="ebutton" type="button" value="导出EXCEL"
								class="btn btn-primary" style="display: none">
						</div>
					</fieldset>
				</div>
				<!-- /. PAGE INNER  -->
			</div>
			<!-- /. PAGE WRAPPER  -->
		</div>

		<!-- /. WRAPPER  -->
		<!-- SCRIPTS -AT THE BOTOM TO REDUCE THE LOAD TIME-->
		<!-- JQUERY SCRIPTS -->
</body>
</html>
